//
//  HWReadHabitViweController.m
//  嗨文
//
//  Created by 响当当 on 2019/1/19.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWReadHabitViweController.h"
#import "HWReadHabitSettingView.h"
#import "HWReadHabitResetViewController.h"

@interface HWReadHabitViweController ()
@property (nonatomic, strong)HWReadHabitSettingView *readHabbitSettingView;//阅读爱好
@property (nonatomic, copy)NSArray *boyArr;
@property (nonatomic, copy)NSArray *girlArr;
@end

@implementation HWReadHabitViweController

- (NSArray *)boyArr
{
    if (!_boyArr)
    {
        _boyArr = [[NSArray alloc]init];
    }
    return _boyArr;
}

- (NSArray *)girlArr
{
    if (!_girlArr)
    {
        _girlArr = [[NSArray alloc]init];
    }
    return _girlArr;
}



- (HWReadHabitSettingView *)readHabbitSettingView
{
    if (!_readHabbitSettingView)
    {
        _readHabbitSettingView = [[HWReadHabitSettingView alloc]initWithFrame:CGRectMake(0,TABBAR_HEIGHT,SCREEN_WIDTH,SCREEN_HEIGHT - TABBAR_HEIGHT - NAVIBAR_HEIGHT)];
        
        _readHabbitSettingView.getBackReadHabbitBlock = ^{
            HWReadHabitResetViewController *vc = [[HWReadHabitResetViewController alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
        };
    }
    return _readHabbitSettingView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"阅读口味"];
    [self setDefaultNav];
    
    [self getBoyHabit];
    [self getGirlHabit];
    
    [self.view addSubview:self.readHabbitSettingView];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self getTasteInfo];
    [self buryPoint];
}

- (void)getTasteInfo
{
    NSDictionary *prarmers = @{
                               @"access_token" : current_User.token,
                               };
    
    WeakSelf(self)
    [NetWorkingManager postRequestUrl:FULL_WEB_URL(KAPI_USERTASTEINFO) withPramater:prarmers sucess:^(id responseObject) {
        NSDictionary *dic = [[NSDictionary alloc]initWithDictionary:responseObject[@"data"]];
        [weakSelf.readHabbitSettingView creatUI:dic boyHabit:weakSelf.boyArr girlHabit:weakSelf.girlArr];
    } failure:^(NSError *error) {
        
    }];
}

- (void)getBoyHabit
{
    NSDictionary *prarmers = @{
                               @"access_token" : current_User.token,
                               @"channel" : @"1"
                               };
    
    WeakSelf(self)
    [NetWorkingManager postRequestUrl:FULL_WEB_URL(KAPI_BOYHABITLIST) withPramater:prarmers sucess:^(id responseObject) {
        weakSelf.boyArr = [NSArray arrayWithArray:responseObject[@"data"]];
    } failure:^(NSError *error) {
        
    }];
}

- (void)getGirlHabit
{
    NSDictionary *prarmers = @{
                               @"access_token" : current_User.token,
                               @"channel" : @"0"
                               };
    
    WeakSelf(self)
    [NetWorkingManager postRequestUrl:FULL_WEB_URL(KAPI_BOYHABITLIST) withPramater:prarmers sucess:^(id responseObject) {
        weakSelf.girlArr = [NSArray arrayWithArray:responseObject[@"data"]];
    } failure:^(NSError *error) {
        
    }];
}


- (void)buryPoint
{
    NSString *lastStayTime = [kUserDefaults objectForKey:@"time"];
    NSString *nowStayTime = [NSString stringWithFormat:@"%ld",[[HWUtilties getNowTimeTimestamp3] integerValue] - lastStayTime.integerValue];
    
    [HWUtilties buryPointWithStayTime:nowStayTime
                            timestamp:[HWUtilties getNowTimeTimestamp3]
                             memberId:current_User.userID
                              fromUrl:nil
                                toUrl:@"/readTaste"
                               fromId:nil
                                 toId:@"d78091dd77d6c379"];
}
@end
